package com.link2room.rodimus.handler.impl;

import com.link2room.common.constant.DefaultValue;
import com.link2room.common.dto.result.base.MemberSessionDto;
import com.link2room.common.dto.threadlocal.ApiThreadLocal;
import com.link2room.common.exception.SysException;
import com.link2room.common.util.L2RAssert;
import com.link2room.rodimus.dto.param.inside.CouponGiveOutInsideParamDto;
import com.link2room.rodimus.feign.rodimus.L2RCouponFeignService;
import com.link2room.rodimus.handler.ISignInDrawAwardHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.link2room.enums.exception.RodimusSysExceptionEnum.SIGN_IN_ERROR;
import static com.link2room.rodimus.constant.CouponConstant.SALE_TYPE.SIGN_IN;

/**
 * Created by LN on 2018/1/9
 */
@Component("signInDrawAwardLotteryHandler")
public class SignInDrawAwardLotteryHandler implements ISignInDrawAwardHandler {
    @Autowired
    private L2RCouponFeignService l2RCouponFeignService;
    @Override
    public void drawAward(String lhotelGroupCode, String type, String value) throws Exception {
        MemberSessionDto memberSession = ApiThreadLocal.getMemberSessionThreadLocal();
        L2RAssert.isTrue(null == memberSession, new SysException(SIGN_IN_ERROR, "请登录."));
        L2RAssert.isTrue(DefaultValue.F.equals(memberSession.getIsMember()), new SysException(SIGN_IN_ERROR, "请先注册会员."));
        L2RAssert.stringBlank(value,"[type] 签到奖品未配置");
        String memberNo = memberSession.getMemberNo();
        String openid = memberSession.getOpenid();

        CouponGiveOutInsideParamDto paramDto = new CouponGiveOutInsideParamDto();
        paramDto.setMemberNo(memberNo);
        paramDto.setOpenid(openid);
        paramDto.setSaleType(SIGN_IN);
        paramDto.setNum(1);
        paramDto.setCouponCode(value);
        l2RCouponFeignService.putOutCoupon(paramDto);
    }
}
